package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.ProdInfo;
import com.ruoyi.system.service.IProdInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 产品Controller
 * 
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/prod")
public class ProdInfoController extends BaseController
{
    @Autowired
    private IProdInfoService prodInfoService;

    /**
     * 查询产品列表
     */
    @RequiresPermissions("system:prod:list")
    @GetMapping("/list")
    public TableDataInfo list(ProdInfo prodInfo)
    {
        startPage();
        List<ProdInfo> list = prodInfoService.selectProdInfoList(prodInfo);
        return getDataTable(list);
    }

    /**
     * 导出产品列表
     */
    @RequiresPermissions("system:prod:export")
    @Log(title = "产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProdInfo prodInfo)
    {
        List<ProdInfo> list = prodInfoService.selectProdInfoList(prodInfo);
        ExcelUtil<ProdInfo> util = new ExcelUtil<ProdInfo>(ProdInfo.class);
        util.exportExcel(response, list, "产品数据");
    }

    /**
     * 获取产品详细信息
     */
    @RequiresPermissions("system:prod:query")
    @GetMapping(value = "/{prodId}")
    public AjaxResult getInfo(@PathVariable("prodId") String prodId)
    {
        return success(prodInfoService.selectProdInfoByProdId(prodId));
    }

    /**
     * 新增产品
     */
    @RequiresPermissions("system:prod:add")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProdInfo prodInfo)
    {
        return toAjax(prodInfoService.insertProdInfo(prodInfo));
    }

    /**
     * 修改产品
     */
    @RequiresPermissions("system:prod:edit")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProdInfo prodInfo)
    {
        return toAjax(prodInfoService.updateProdInfo(prodInfo));
    }

    /**
     * 删除产品
     */
    @RequiresPermissions("system:prod:remove")
    @Log(title = "产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prodIds}")
    public AjaxResult remove(@PathVariable String[] prodIds)
    {
        return toAjax(prodInfoService.deleteProdInfoByProdIds(prodIds));
    }
}
